﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Emoney.Spider.Basic
{
    public static class DelHtmlTags
    {
        public static string DelHtml(string _content, HtmlTags Tags)
        {
            string _rel = _content;
            try
            {
                if (!string.IsNullOrEmpty(_content))
                {
                    if (Tags.t_html == true)
                    {
                        _rel = Regex.Replace(_rel, @"<[^>]+>", "");
                    }
                    else
                    {
                        if (Tags.t_a == true)
                        {
                            _rel = Regex.Replace(_rel, @"<a[^>]*>|</a>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_table == true)
                        {
                            _rel = Regex.Replace(_rel, @"<table[^>]*>|</table>|<tbody[^>]*>|</tbody>|<tr[^>]*>|</tr>|<th[^>]*>|</th>|<td[^>]*>|</td>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_p == true)
                        {
                            _rel = Regex.Replace(_rel, @"<p[^>]*>|</p>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_font == true)
                        {
                            _rel = Regex.Replace(_rel, @"<font[^>]*>|</font>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_div == true)
                        {
                            _rel = Regex.Replace(_rel, @"<div[^>]*>|</div>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_span == true)
                        {
                            _rel = Regex.Replace(_rel, @"<span[^>]*>|</span>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_img == true)
                        {
                            _rel = Regex.Replace(_rel, @"<img[^>]*>|</img>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_script == true)
                        {
                            _rel = Regex.Replace(_rel, @"<script[\S\s]*?</script>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_b == true)
                        {
                            _rel = Regex.Replace(_rel, @"<b[^>]*>|</b>|<strong[^>]*>|</strong>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_br == true)
                        {
                            _rel = Regex.Replace(_rel, @"<br[^>]*>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_h == true)
                        {
                            _rel = Regex.Replace(_rel, @"<h[1-7][^>]*>|</h[1-7]>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_hr == true)
                        {
                            _rel = Regex.Replace(_rel, @"<hr[^>]*>|</hr>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_form == true)
                        {
                            _rel = Regex.Replace(_rel, @"<form[\S\s]*?</form>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_frame == true)
                        {
                            _rel = Regex.Replace(_rel, @"<frame[\S\s]*?</frame>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_li == true)
                        {
                            _rel = Regex.Replace(_rel, @"<ul[^>]*>|</ul>|<li[^>]*>|</li>|<dl[^>]*>|</dl>|<dt[^>]*>|</dt>|<dd[^>]*>|</dd>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_iframe == true)
                        {
                            _rel = Regex.Replace(_rel, @"<iframe[\S\s]*?</iframe>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_sub == true)
                        {
                            _rel = Regex.Replace(_rel, @"<sub[^>]*>|</sub>|<sup[^>]*>|</sup>", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_form == true)
                        {
                            _rel = Regex.Replace(_rel, @"<!--[\S\s]*?-->", "", RegexOptions.IgnoreCase);
                        }
                        if (Tags.t_style == true)
                        {
                            _rel = Regex.Replace(_rel, @"<style[\S\s]*?</style>|<style[^>]*>|</style>", "", RegexOptions.IgnoreCase);
                        }
                    }
                }
            }
            catch { }
            return _rel;
        }
    }
}
